<!--
 * @description  :情报登记/派发/处置列表
 * @descriptionDetail:情报登记/派发/处置列表
 * @copyright    : 浙江烟草
 * @author       : dw
 * @create       : 2022-11-13 18:15:41
-->
<template>
  <view class="page">
    <!-- #ifdef H5-ONLY -->
    <theme-navbar :is-white="false" :title="navTitle" :custom-back="goBack" style="z-index: 99999">
    </theme-navbar>
    <!-- #endif -->
    <view class="key-search" :style="{'top': isHideNav ? 0 : '44px'}">
      <u-search
        bg-color="#fff"
        shape="round"
        :clearabled="true"
        actionText="确定"
        :showAction="true"
        :animation="true"
        placeholder="线索编号"
        v-model="searchKey"
        @custom="toSearchList"
      ></u-search>
    </view>
    <list-view
      style="margin-top:50rpx"
      :i="0"
      :index="0"
      :load-data="loadData"
      :top="getListViewTop()"
      :bottom="getListViewBottom()"
      :init-load="false"
      ref="mescrollItem0"
    >
      <view slot-scope="d">
        <u-swipe-action
          :show="d.data.show"
          :index="d.data.uuid"
          :disabled="d.data.swiperDisabled"
          @click="swiperClick"
          @open="swiperOpen"
          :options="d.data.swiperOption"
        >
          <view class="list-lay">
            <list-item-intelligence-register :fromType="fromType" :itemInfo="d.data"></list-item-intelligence-register>
          </view>
        </u-swipe-action>
      </view>
    </list-view>
    <view class="submit-btns btn-other-cls" v-if="fromType == 'register'">
      <u-button class="u-btn" type="primary" @click="addPersonInvolved">
        登记
      </u-button>
    </view>
  </view>
</template>

<script>
import MescrollMoreMixin from "@/components/mescroll-uni/mixins/mescroll-more.js";
import ListView from "@/components/list_view.vue";
import listItemIntelligenceRegister from "./components/listItemIntelligenceRegister.vue";
import inteligenceService from '@/service/intelligence/intelligence.service.js';
import {INTELLIGENCE_STATUS,} from "@/service/intelligence/mapping/enum.js";
import {uuid,} from "@/common/util.js";
export default {
  components: {
    ListView,
    listItemIntelligenceRegister,
  },
  mixins: [MescrollMoreMixin,],
  data() {
    return {
      user: this.$storage.get(this.$rp.common.USER),
      fromType:"", // register  feedback
      searchKey:"",
      curRecord: undefined,
      customStyle: {
        "margin-left": "5px",
        "margin-right": "5px",
        "padding-left": "15px",
        "padding-right": "15px",
        "margin-bottom": "10px",
      },
      topSelf:"",
    }
  },
  onLoad(opt) {
    this.showDefaultTitle = false;
    this.fromType = opt.fromType;
    console.log(this.fromType);
    if(this.fromType == 'register'){
      this.updateMixinTitle("情报登记派发");
    }else if(this.fromType == 'feedback'){
      this.updateMixinTitle("情报处置反馈");
    }
  },
  mounted() {
  },
  methods: {
    getListViewTop() {
      let p = uni.upx2px(64) + uni.upx2px(10);
      return p  + "px";
    },
    getListViewBottom(){
      return uni.upx2px(140) + 10;
    },
    getListTop(){
      let p =  44 + uni.upx2px(10) + this.$u.sys().statusBarHeight;
      // #ifdef H5-DINGDING || H5-WECHAT
      p = uni.upx2px(10) + this.$u.sys().statusBarHeight;
      // #endif
      return p  + "px";
    },
    toSearchList(e){
      this.getMescroll(0).triggerDownScroll();
    },
    loadData(page) {
      let type = "";
      if(this.fromType == 'feedback'){
        type = "invest";
      }else if(this.fromType == 'register'){
        type = "add";
      }
      return new Promise((resolve, reject) => {
        inteligenceService.cluePage({
          limit: page.size,
          page:page.num,
          menuCode: null,
          paras:{
            type: type,
            clueCode:this.searchKey,
            manager : 0,
          },
        }).then(res => {
          this.topSelf = res.msg || '';
          if(res.success){
            this.updateSwiperOptionByRes(res.data);
            resolve({
              data:{
                totalCount:res.count,
                list:res.data,
              },
            })
          }else{
            this.$u.toast(res.msg);
            resolve({
              data:{
                totalCount:0,
                list:[],
              },
            })
          }
        }).catch(e => {
          console.log(e);
          this.$u.toast('请求失败:' + e);
          resolve({
            data:{
              totalCount:0,
              list:[],
            },
          })
        })
      });
    },
    swiperClick(index1, index){
      let datas = this.$refs.mescrollItem0.listDatas;
      let cur = -1;
      for (let i = 0; i < datas.length; i++) {
        if(datas[i].uuid == index1){
          cur = i;
          break;
        }
      }
      if(cur == -1){
        this.$u.toast("选中数据无效");
        return;
      }
      this.$refs.mescrollItem0.listDatas.map((val, idx) => {
        val.show = false;
      });
      this.curRecord = datas[cur];
      let opts = datas[cur].swiperOption;
      let msg = ''; let upOrgName = ''; let upOrgUuid = '';
      if(opts[index].action == 'del'){
        this.$modal.showLoading('正在删除...');
        inteligenceService.deleteClueByIds([datas[cur].uuid,]).then(res => {
          this.$modal.hideLoading();
          if(res.success) {
            this.getMescroll(0).triggerDownScroll();
            this.$u.toast('删除成功');
          } else {
            this.$u.toast(res.msg);
          }
        }).catch(e => {
          console.log(e);
          this.$modal.hideLoading();
          this.$u.toast("删除失败:" + e);
        });
      }
    },
    updateSwiperOptionByRes(arr){
      arr && arr.forEach(itm => {
        itm.show = false;
        itm.swiperDisabled = true;
        itm.swiperOption = [];
        if(itm.status === INTELLIGENCE_STATUS.DRAFT.value && itm.current){
          itm.swiperDisabled = false;
          itm.swiperOption.push({
            text: '删除',
            action:'del',
            style: { backgroundColor: this.$theme.u_type_error,},
          });
        }
      });
    },
    addPersonInvolved(){
      this.setRouteParam({});
      this.$u.route({
        url:"/pages/intelligence/intelligenceFilesAdd/registration",
        params:{
          fromType: this.fromType,
          from: 0,
          topSelf: this.topSelf,
        },
      });
    },
    updateBackState(param){
      if(param.refresh){
        this.getMescroll(0).triggerDownScroll();
      }
    },
    swiperOpen(index){
      this.$refs.mescrollItem0.listDatas.map((val, idx) => {
        this.$refs.mescrollItem0.listDatas[idx].show = index == val.id;
      });
    },
  },
}
</script>

<style scoped lang="scss">
	@import "@/style/common/rightMenu.scss";
	.page {
		background-color: #F3F4F5;
		padding: 0;
	}
	.key-search{
		width: 100%;
		position: fixed;
		background-color: white;
		z-index: 99;
		padding: $cm-search-padding-row $cm-search-padding-column;
		//#ifdef H5-DINGDING
		top: 0;
		//#endif
		//#ifndef H5-DINGDING
		top: 44px;
		//#endif
	}
	.pop-content-lay{
		padding: 20rpx;
		display: flex;
		height: 100%;
		flex-direction: column;
		justify-content: flex-start;
	}
	::v-deep .lt-right-value{
    margin-left:0rpx;
    font-size:28rpx;
  }
  ::v-deep .u-swipe-action{
  background-color: #F3F4F5 !important;
  }
  ::v-deep .u-swipe-content{
    background-color: white;
    border-radius: 32rpx;
    margin: 10rpx 20rpx;
  }
	.list-lay{
		padding: $cm-conent-padding-column $cm-content-paddng-row;
	}
	.tag-lay-btns{
		margin-top: 32rpx;
		display: flex;
		flex-direction: row;
		justify-content: space-around;
		width: 100%;
		uni-button{
			flex: 0.4;
		}
	}
</style>
